﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace eLearning.Business
{
    public class ClassRepository
    {
        // Create an instance of entities framework
        eLearningEntities entities = new eLearningEntities();
        public List<Class> GetAll()
        {
            return (from c in entities.Classes select c).ToList();
        }
        public Class GetSingle(int id)
        {
            return (from c in entities.Classes where c.ClassId == id select c).FirstOrDefault();
        }
        public void Create(Class _object)
        {
            entities.AddToClasses(_object);
            entities.SaveChanges();
        }
        public void Update(Class _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.Classes where _list.ClassId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
    }
}